/*
 * Copyright (C) 2018 The Asiainfo-Ability Authors
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package org.asiainfo.ability.manager.dao.column;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.asiainfo.ability.manager.code.PackageState;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: visen
 * @Date: 2018/1/16
 * @Description:
 */
public class PackageStateHandler implements TypeHandler<PackageState> {

    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, PackageState state, JdbcType jdbcType)
            throws SQLException {
        preparedStatement.setInt(i, state.getValue());
    }

    @Override
    public PackageState getResult(ResultSet resultSet, String s) throws SQLException {
        return PackageState.valueOf(resultSet.getInt(s));
    }

    @Override
    public PackageState getResult(ResultSet resultSet, int i) throws SQLException {
        return PackageState.valueOf(resultSet.getInt(i));
    }

    @Override
    public PackageState getResult(CallableStatement callableStatement, int i) throws SQLException {
        return PackageState.valueOf(callableStatement.getInt(i));
    }
}
